package problem14;

//14.最长公共前缀
//https://leetcode.cn/problems/longest-common-prefix/

class Solution {
    public String longestCommonPrefix(String[] strs) {
        int minlen = 0x3f3f3f3f;
        for(String s : strs) {
            minlen = Math.min(minlen, s.length());
        }
        System.out.println(minlen);
        int i = 0;
        for(; i<minlen; i++) {
            char ch = strs[0].charAt(i);
            for(int j = 1; j<strs.length; j++) {
                if(strs[j].charAt(i) != ch) {
                    return strs[0].substring(0, i);
                }
            }
        }
        return strs[0].substring(0, i);
    }
}